package com.komodo.island.gdx.dialog;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.actors.Button;
import com.badlogic.gdx.scenes.scene2d.actors.Button.ClickListener;
import com.badlogic.gdx.scenes.scene2d.actors.Image;
import com.komodo.island.gdx.Input;
import com.komodo.island.gdx.KomodoIsland;
import com.komodo.island.gdx.Persistence;
import com.komodo.island.gdx.screen.MainMenuScreen;
import com.komodo.island.gdx.screen.Screen;

public class ExitDialog extends Dialog {

	protected Image bgImage;
	protected Image confirmationText;
	protected Button yesButton;
	protected Button noButton;
	public Image siKomo;

	public ExitDialog(float width, float height, boolean stretch,
			Screen screen, Texture texture,KomodoIsland komodoIsland) {
		super(width, height, stretch, screen, texture,komodoIsland);
		// TODO Auto-generated constructor stub
		ID = Input.DIALOG_EXIT;
	}

	@Override
	public void init() {
		// TODO Auto-generated method stub
		// textureName = Constants.dialogTexName;
		// initByName();
		// setBackground(0, 0, 480, 320);
		//

		background = new Image(backgroundName, new TextureRegion(
				komodoIsland.menuTexture, 0, 0, 480, 320));

		bgImage = new Image("bg", new TextureRegion(texture, 0, 0, 351, 194));
		confirmationText = new Image("text", new TextureRegion(texture,
				351 + 200, 71, 164, 28));
		siKomo = new Image("komo", new TextureRegion(texture, 351 + 200 + 179,
				0, 100, 102));

		yesButton = new Button("yes button", new TextureRegion(texture, 351, 0,
				100, 58), new TextureRegion(texture, 351 + 100, 0, 100, 58));
		noButton = new Button("no button", new TextureRegion(texture, 351, 58,
				100, 58), new TextureRegion(texture, 351 + 100, 58, 100, 58));

	}

	@Override
	public void addElements() {
		// TODO Auto-generated method stub

		addActor(background);
		addActor(bgImage);
		addActor(confirmationText);
		addActor(siKomo);
		addActor(yesButton);
		addActor(noButton);
	}

	@Override
	public void setThePosition() {
		// TODO Auto-generated method stub
		bgImage.x = 240 - 351 / 2;
		bgImage.y = 160 - 194 / 2;

		siKomo.x = bgImage.x + 28;
		siKomo.y = bgImage.y + 194 - siKomo.height - 14;

		confirmationText.x = siKomo.x + bgImage.width / 3 - 10;
		confirmationText.y = bgImage.y + 64 * 2 + 14;

		yesButton.x = bgImage.x + 100;
		yesButton.y = bgImage.y + 14;

		noButton.x = yesButton.x + yesButton.width + 30;
		noButton.y = yesButton.y;

	}

	@Override
	public void setTheListener() {
		// TODO Auto-generated method stub
		yesButton.clickListener = new ClickListener() {
			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
				if (Persistence.sound)
					komodoIsland.dialogSound.play(1);
				if (screen.previousScreen != null)
					screen.exitScreen();
				else if (screen instanceof MainMenuScreen) {
					komodoIsland.dispose();
					komodoIsland.exitAll();
					System.exit(0);

				}
			}
		};

		noButton.clickListener = new ClickListener() {

			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
				if (Persistence.sound)
					komodoIsland.dialogSound.play(1);
				screen.setScreenToRun();
			}
		};

	}

}
